home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / beebe / c / dvidjp < prev    next >
Encoding:
Text File  |  1992-01-14  |  16.5 KB  |  578 lines

  1. /* A few lines modified by GNS 13-01-92 --- all are lines like:
  2. #endif  /*something*/          where I added the comment brackets*/
  3. /*
  4. I just got myself a brand new HP Desk Jet Plus printer to use with TeX.
  5. I and a number of other people asked the net for sources to one of the many
  6. DeskJet drivers which must be out there, but there was no response.  I
  7. searched all the archives I could find, with similarly unsuccessful
  8. results.
  9.  
  10. So I took the dvijet driver from the Beebe release and modified it for
  11. the desk jet plus.  It might be called (as by some) a "vanilla" driver
  12. because it doesn't use downloadable fonts, but downloadable fonts
  13. requires an extra memory cartridge -- for that I would have just
  14. as soon bought the IIp.   I did include some memory compaction, though,
  15. which reduces file size and transfer time by 50 - 70 %  So it's not
  16. quite vanilla.  The various compaction schemes can be switched off
  17. at compile time if the old Desk Jet doesn't support them (I have no
  18. idea).
  19.  
  20. I include the modified source below.  It requires the rest of the
  21. Beebe driver code, which is commonly available -- eg,
  22. at ymir.claremont.edu & science.utah.edu in aps:<tex.dvi>  ... whatever.
  23.  
  24. Be warned that the whole BEEBE dvi package is about 1MB.  This file is
  25. only a tiny part of it.
  26.  
  27. Hope this is helpful.
  28.  
  29. Paul Kirkaas
  30. kirkaas@cs.ucla.edu
  31.  
  32. ----------------------------------------------------------
  33. /* -*-C-*- dvidjp.c */
  34. /*-->dvidjp*/
  35. /**********************************************************************/
  36. /******************************* dvidjp *******************************/
  37. /**********************************************************************/
  38.  
  39. /* Driver for HP DeskJet Plus printer -- modified from
  40.  * Beebe Laser Jet driver
  41.  * by Paul Kirkaas (kirkaas@cs.ucla.edu) 22 May 1990
  42.  *    patch 1 -- bugs in YOFF & COMPACTION fixed 23 May 1990
  43.  *
  44.  * Employs 3 types of data compaction for greater efficiency --
  45.  * up to 60 - 70% reduction in output file size.  Each compaction 
  46.  * scheme can be switched on or off independently by defining any
  47.  * or all of:
  48.  *
  49.  * XOFF -- X offset -- instead of a string of leading zeros, offset
  50.  *     by appropriate amount.  Minimal savings when used  with
  51.  *    COMPACTION mode set.
  52.  *
  53.  * YOFF -- Y offset -- compress multiple blank lines into a single
  54.  *    y skip command.
  55.  *
  56.  * COMPACTION -- Uses mode 2 compaction on Desk Jet Plus -- this is
  57.  *    the trickiest but most effective compression modification.
  58.  *    This is the likliest part to have a bug.
  59.  *    Lots of cleaning up can be done here.
  60.  *
  61.  * If you have an old Desk Jet (not a Plus) it may not have
  62.  * all these abilities -- try undfining some of these switches.
  63.  *
  64.  * It should run straight with the Beebe driver set; you might
  65.  * have to make some adjustments.  I have personally only run
  66.  * it on an AT&T System V 3b1.
  67.  *
  68.  * Please let me know if you make any improvements or repairs.
  69.  * Thanks
  70.  *
  71.  * Good Luck.
  72.  */
  73.  
  74. #include "dvihead.h"
  75.  
  76. /**********************************************************************/
  77. /************************  Device Definitions  ************************/
  78. /**********************************************************************/
  79.  
  80. /* All output-device-specific definitions go here.  This section must
  81. be changed when modifying a dvi driver for use on a new device */
  82.  
  83. #undef HPLASERJET
  84. #define  HPLASERJET       1        /* conditional compilation flag */
  85. #define  HPDESKJET       1        /* conditional compilation flag */
  86.         /* Include the following line for Y offsets*/
  87. #define YOFF    1
  88.         /* Include the following line for using temporary X offsets*/
  89. #define XOFF    1
  90.         /* Include the following line for Mode 2 Compaction */
  91. #define    COMPACTION    1    
  92. /*
  93. #define COMPACTION    0
  94. */
  95.  
  96. #define VERSION_NO    "2.10"        /* DVI driver version number */
  97.  
  98. #define  DEVICE_ID    (comp ? \
  99.         "Hewlett-Packard Desk Jet plus (from LaserJet)\n\
  100.     WITH Data Compaction for faster I/O" : \
  101.         "Hewlett-Packard Desk Jet plus (from LaserJet)\n\
  102.     with-OUT Data Compaction I/O" )
  103.                 /* this string is printed at runtime */
  104. #define OUTFILE_EXT    (comp ? "djc" : "dj")
  105.  
  106. #define  DEFAULT_RESOLUTION 300        /* default dots/inch on HP Desk Jet */
  107.  
  108. #define  BYTE_SIZE        8        /* output file byte size */
  109.  
  110. #undef STDRES
  111. #define STDRES  1            /* 0 for low-resolution devices */
  112.  
  113. #define  XDPI        300        /* HP Laser Jet horizontal dots/inch */
  114. #define  XPSIZE        8        /* horizontal paper size in inches */
  115.  
  116. #define  XSIZE        (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
  117.                 (2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
  118.                     /* number of horizontal dots; */
  119.                     /* MUST BE multiple of */
  120.                     /* 2*HOST_WORD_SIZE */
  121. #define  XWORDS        ((XSIZE + HOST_WORD_SIZE - 1)/HOST_WORD_SIZE)
  122.                     /* number of words in rows  */
  123.                     /* of bitmap array */
  124.  
  125. #define  YDPI        300        /* HP Laser Jet vertical dots/inch */
  126.  
  127. #define  YPSIZE        11        /* vertical paper size in inches */
  128. #define  YSIZE        (YDPI*YPSIZE)    /* number of vertical dots */
  129.  
  130. /* The printer bit map (must have an even number of columns). */
  131.  
  132. #define XBIT ((1+2*XWORDS)/2)
  133. #define YBIT YSIZE
  134. #if    (IBM_PC_LATTICE | IBM_PC_MICROSOFT | IBM_PC_WIZARD)
  135. #undef SEGMEM
  136. #define SEGMEM 1 /* ( ((long)XBIT * (long)YBIT) > 65536L ) */
  137. #endif
  138. int comp = COMPACTION;        /* compaction flag -- reset in option.h */
  139.  
  140. #include "bitmap.h"
  141.  
  142. #include "main.h"
  143. #undef STDMAG
  144. #undef RESOLUTION
  145. #define STDMAG 1500
  146. #define    RESOLUTION    (((float)STDMAG)/5.0)    /* dots per inch */
  147. #include "abortrun.h"
  148. #include "actfact.h"
  149. #include "alldone.h"
  150. #include "chargf.h"
  151. #include "charpk.h"
  152. #include "charpxl.h"
  153. #include "clrbmap.h"
  154. #include "clrrow.h"
  155. #include "dbgopen.h"
  156.  
  157. /*-->devinit*/
  158. /**********************************************************************/
  159. /****************************** devinit *******************************/
  160. /**********************************************************************/
  161.  
  162. void
  163. devinit(argc,argv)        /* initialize device */
  164. int argc;
  165. char *argv[];
  166. {
  167.     (void)getbmap();
  168.     OUTS("\033E");    /* printer reset */
  169.     OUTS("\033&l0L");    /* Disable perforation skip */
  170. /* OUTS("\033*rB");    /* End graphics */
  171.     OUTS("\033*t300R");    /* printer resolution */
  172. if (comp)
  173.     OUTS("\033*b2M");    /* Select Compacted Graphics Mode Two */
  174. else
  175.     OUTS("\033*b0M");    /* Select Full Graphics Mode */
  176.  
  177.     OUTS("\033*r0A");    /* Start graphics, at leftmost position */
  178. }
  179.  
  180. /*-->devterm*/
  181. /**********************************************************************/
  182. /****************************** devterm *******************************/
  183. /**********************************************************************/
  184.  
  185. void
  186. devterm()            /* terminate device */
  187. {
  188.     OUTS("\033E");    /* printer reset*/
  189. }
  190.  
  191. #include "dvifile.h"
  192. #include "dviinit.h"
  193. #include "dviterm.h"
  194. #include "dispchar.h"
  195. #include "f20open.h"
  196. #include "fatal.h"
  197. #include "fillrect.h"
  198. #include "findpost.h"
  199. #include "fixpos.h"
  200. #include "fontfile.h"
  201. #include "fontsub.h"
  202. #include "getbmap.h"
  203. #include "getbytes.h"
  204. #include "getfntdf.h"
  205. #include "getpgtab.h"
  206. #include "initglob.h"
  207. #include "inch.h"
  208. #include "loadchar.h"
  209. #include "movedown.h"
  210. #include "moveover.h"
  211. #include "moveto.h"
  212. #include "nosignex.h"
  213. #include "openfont.h"
  214. #include "option.h"
  215.  
  216. /*-->outline*/
  217. /**********************************************************************/
  218. /****************************** outline *******************************/
  219. /**********************************************************************/
  220.  
  221. void
  222. outline(pbit)
  223. UNSIGN32 *pbit;                /* pointer to raster line */
  224.  
  225. /*************************************************************************
  226. Use machine-specific coding here for efficiency.  For TOPS-20, we encode
  227. 9 bytes from every pair  of 36-bit words.
  228.  
  229. For each raster line on the paper, the Laser Jet expects a binary  8-bit
  230. byte stream of the form
  231.  
  232.     <ESC>*bnnnWxxxxxxx ... xxxxxxx
  233.                <--- nnn bytes --->
  234.  
  235. where each byte contains, in order from high to low bit, a left-to-right
  236. bit pattern.  No  end-of-line marker  is required;  the escape  sequence
  237. automatically causes a new raster line to be started.
  238. *************************************************************************/
  239.  
  240. {
  241.     register UNSIGN32 w_even,w_odd;
  242.     register UNSIGN32 *p;
  243.     register BYTE *pbuf;
  244.     BYTE buf[1+(XSIZE+7)/8];        /* space for EOS + n 8-bit bytes */
  245.     register INT16 i,last_word;
  246.     int ic,jc;            /* just counters */
  247.     unsigned char * endb;    /* pointer to end of buf */
  248.     unsigned char greystr[129]; /* Max length of 127 in compacted mode 2 */
  249.     unsigned char * greyp;    /* Pointer to greystr[]  */
  250.     unsigned char outstr[999];    /* Compacted mode 2 output string */
  251.     unsigned char * outp;    /* Pointer to outstr[]  */
  252.     unsigned char * endob;    /* pointer to end of outstr */
  253.     unsigned char cmp;        /* Comparison variable */
  254.     int outsz;            /* Size of outstr -- since includes NULLs */
  255.     int count;
  256.     int gcnt;    /* Length of grey runs */
  257.  
  258.  
  259. #if    IBM_PC_MICROSOFT
  260.     for (last_word = XBIT - 1;
  261.     (last_word >= 1) && (*(UNSIGN32*)normaddr(pbit,last_word) == 0);
  262.     --last_word)
  263.         ;                /* trim white space a word at a time */
  264. #else
  265.     p = pbit + XBIT - 1;        /* point to last word on line */
  266.     for (last_word = XBIT - 1; (last_word >= 1) && (*p == 0); --last_word)
  267.         --p;                /* trim white space a word at a time */
  268. #endif
  269.  
  270.     p = pbit;
  271.     pbuf = &buf[0];
  272.     for (i = 0; i <= last_word; i += 2)    /* loop over trimmed raster */
  273.     {
  274.         w_even = (*p++);
  275.         w_odd = (*p++);
  276.  
  277. #if    (HOST_WORD_SIZE == 36)
  278.     *pbuf++ = (BYTE)( (w_even >> 28) & 0xff);
  279.     *pbuf++ = (BYTE)( (w_even >> 20) & 0xff);
  280.     *pbuf++ = (BYTE)( (w_even >> 12) & 0xff);
  281.     *pbuf++ = (BYTE)( (w_even >>  4) & 0xff);
  282.     *pbuf++ = (BYTE)( ((w_even <<  4) | (w_odd >> 32)) & 0xff);
  283.     *pbuf++ = (BYTE)( (w_odd  >> 24) & 0xff);
  284.     *pbuf++ = (BYTE)( (w_odd  >> 16) & 0xff);
  285.     *pbuf++ = (BYTE)( (w_odd  >>  8) & 0xff);
  286.     *pbuf++ = (BYTE)( (w_odd       ) & 0xff);
  287. #else /* HOST_WORD_SIZE == 32 */
  288.     /* encode 8 bytes at a time on 32-bit machines */
  289.     *pbuf++ = (BYTE)( (w_even >> 24) & 0xff);
  290.     *pbuf++ = (BYTE)( (w_even >> 16) & 0xff);
  291.     *pbuf++ = (BYTE)( (w_even >>  8) & 0xff);
  292.     *pbuf++ = (BYTE)( (w_even      ) & 0xff);
  293.     *pbuf++ = (BYTE)( (w_odd  >> 24) & 0xff);
  294.     *pbuf++ = (BYTE)( (w_odd  >> 16) & 0xff);
  295.     *pbuf++ = (BYTE)( (w_odd  >>  8) & 0xff);
  296.     *pbuf++ = (BYTE)( (w_odd       ) & 0xff);
  297. #endif
  298.  
  299.     }
  300.  
  301.     *pbuf = '\0';            /* trailing EOS marker */
  302.  
  303.     last_word |= 1;            /* make last_word ODD */
  304.     for (i = ((last_word+1)*HOST_WORD_SIZE)/8;
  305.         (*(--pbuf) == '\0') && (i > 1); --i)
  306.     ;    /* trim trailing zero bytes, leaving at least one */
  307.     last_word = i;
  308. #ifdef XOFF
  309.     /* Trim leading zero bytes & do appropriate Temporary X offset */
  310.     OUTS("\033*b"); /* Set up for raster transfer */
  311.     pbuf=buf;
  312.     for (ic=0; !buf[ic] && ic<last_word ; ic++, pbuf++)
  313.     ;
  314.     if (ic>10) /* Do an X-shift */
  315.     {
  316.         OUTF("%dx",8*ic); /* Shift by 8*ic # of blank pixels */
  317.     }
  318.     else    /* don't bother */
  319.     { pbuf = buf; ic = 0; }
  320.  
  321.     endb = &buf[last_word];
  322.  
  323. if (comp)
  324.   {
  325.     greyp = greystr;
  326.     outp = outstr;
  327.     outsz = gcnt = 0;
  328.     endb = &buf[last_word];
  329.     while (pbuf <= endb)
  330.     {
  331.       cmp = *pbuf;
  332.       for (count = 0; count<127 && pbuf<=endb && cmp==*pbuf; count ++, pbuf++)
  333.     ;
  334.       if (count==0){printf("DANGER DANGER ***COUNT IS ZERO***!!!\n");exit(0);}
  335.       if (count <= 3) /* No run yet -- just put them in greystr */
  336.     {
  337.       gcnt += count;
  338.       for (jc = 0; jc < count ; jc ++)
  339.         {
  340.         *greyp = cmp;
  341.         greyp++;
  342.         }
  343.       if (gcnt >= 124)  /* Can't have more than 127, so ... */
  344.         {
  345.         outstr[outsz] = gcnt-1;
  346.         outsz++;
  347.         for (jc = 0; jc < gcnt; jc ++)
  348.           {
  349.             outstr[outsz + jc] = greystr[jc];
  350.           }
  351.         outsz += gcnt;
  352.         gcnt = 0;
  353.         greyp = greystr;
  354.         continue;
  355.         }
  356.     }
  357.       else /* We have a run of 4 or more */
  358.     {
  359.         if (gcnt) /* Flush our accumilated grey */
  360.         {
  361.         outstr[outsz] = gcnt-1;
  362.         outsz++;
  363.         for (jc = 0; jc < gcnt; jc ++)
  364.           {
  365.             outstr[outsz + jc] = greystr[jc];
  366.           }
  367.         outsz += gcnt;
  368.         gcnt = 0;
  369.         greyp = greystr;
  370.         }
  371.         outstr[outsz] = (unsigned char) (1-count); /* Is this cast right? */
  372.         outsz ++;
  373.         outstr[outsz] = cmp;
  374.         outsz++;
  375.     }
  376.     }
  377.     if (gcnt) /* Flush our accumilated grey */
  378.       {
  379.     outstr[outsz] = gcnt-1;
  380.     outsz++;
  381.     for (jc = 0; jc < gcnt; jc ++)
  382.       {
  383.         outstr[outsz + jc] = greystr[jc];
  384.       }
  385.     outsz += gcnt;
  386.     gcnt = 0;
  387.     greyp = greystr;
  388.       }
  389.     OUTF("%dW",outsz); /* How much is coming ... */
  390.     endob = outstr + outsz -1; /* End of the outstr */ 
  391.     for (outp = outstr; outp <= endob; outp++ )
  392.         OUTC(*outp);
  393.  
  394.   }
  395.  else 
  396.   {
  397.     OUTF("%dW",(int)last_word-ic); /* How much is coming ... */
  398.     /* cannot use fprintf with %s format because of
  399.                    NUL's in string, and it is slow anyway */
  400.     for (i = ic; i < last_word; ++pbuf,++i)
  401.         OUTC(*pbuf);
  402.   }
  403. #else
  404.     OUTF("\033*b%dW",(int)last_word);
  405.     pbuf = &buf[0];    /* cannot use fprintf with %s format because of
  406.                    NUL's in string, and it is slow anyway */
  407.     for (i = 0; i < last_word; ++pbuf,++i)
  408.         OUTC(*pbuf);
  409. #endif /*XOFF */
  410. }  
  411.  /*-->prtbmap*/
  412. /**********************************************************************/
  413. /****************************** prtbmap *******************************/
  414. /**********************************************************************/
  415.  
  416. void
  417. prtbmap()
  418.  
  419. {
  420.     register UNSIGN32 *p;
  421.     register INT16 j,k,ybottom,ytop;
  422. #ifdef YOFF
  423.     int ycnt = 0;
  424. #endif /*YOFF*/
  425. /*   OUTS("\033E");    /* printer reset */ /*    OUTS("\033&l0L");    /* Disable
  426. perforation skip */ /*    OUTS("\033*rB");    /* End graphics */ /*   
  427. OUTS("\033*t300R");    /* printer resolution */ if (comp)
  428.     OUTS("\033*b2M");    /* Select Compacted Graphics Mode Two */
  429. else
  430.     OUTS("\033*b0M");    /* Select Full Graphics Mode */
  431.  
  432.     OUTS("\033*r0A");    /* Start graphics, at leftmost position */
  433.  
  434.     if (DBGOPT(DBG_PAGE_DUMP))
  435.     {
  436.     INT16 k1,k2,k3;
  437.  
  438.     for (k3 = 0; k3 < XBIT; (k3 += 7, ++p))
  439.     {    /*  print bitmap 7 words at a pass */
  440.         k1 = k3;
  441.         k2 = MIN(XBIT,k1+7);
  442.         (void)printf("prtbmap()...bitmap words %d..%d",k1,k2-1);
  443.         NEWLINE(stdout);
  444.         (void)printf("     ");
  445.         for (k = k1; k < k2; ++k)
  446.             (void)printf("%10d",k*HOST_WORD_SIZE);
  447.         NEWLINE(stdout);
  448.         for (j = YBIT-1; j >= 0; --j)
  449.         {
  450.             p = BITMAP(j,0);
  451.         for (k = 0; k < XBIT; (++k,++p))
  452.         {
  453.                 if (*p)    /* print non-blank raster line */
  454.             {
  455.                 p = BITMAP(j,k1);
  456.             (void)printf("%5d:",j);
  457.             for (k = k1; k < k2; (++k,++p))
  458.                 (void)printf(" %09lx",*p);
  459.             NEWLINE(stdout);
  460.             break;    /* exit loop over k */
  461.             }
  462.         }
  463.         }
  464.     }
  465.     }
  466.  
  467.     (void)clearerr(plotfp);
  468.  
  469. #if    ZAPTHISOUT
  470.     k = -1;        /* find top non-zero raster */
  471.     for (j = YBIT-1; (j > 0) && (k < 0); --j)  /* loop over raster lines */
  472.     {
  473.     p = BITMAP(j,XBIT-1);
  474.     for (k = XBIT - 1; ((k >= 0) && (*p == 0)); --k)
  475.         --p;        /* trim white space */
  476.     }
  477.     ytop = j;
  478. #else
  479.     ytop = YBIT-1;
  480. #endif
  481.  
  482.     k = -1;        /* find bottom non-zero raster */
  483.     for (j = 0; (j < ytop) && (k < 0); ++j) /* loop over raster lines */
  484.     {
  485.  
  486. #if    IBM_PC_MICROSOFT
  487.     for (k = XBIT - 1;((k >= 0) && (*BITMAP(j,k) == 0));--k)
  488.         ;        /* trim white space */
  489. #else
  490.     p = BITMAP(j,XBIT-1);
  491.     for (k = XBIT - 1; ((k >= 0) && (*p == 0)); --k)
  492.         --p;        /* trim white space */
  493. #endif
  494.  
  495.     }
  496.     ybottom = MAX(0,j-1);
  497.  
  498. #if    ZAPTHISOUT
  499.     for (j = ytop; (j >= ybottom); --j)
  500.         {
  501.     OUTF("%5d:",(int)j);
  502.         for (k = 0; k < XBIT; ++k)
  503.             OUTF(" %9x",*BITMAP(j,k));
  504.     NEWLINE(plotfp);
  505.         }
  506. #endif
  507.  
  508.  
  509. #ifdef YOFF
  510.     ycnt = 0;
  511.     for (j = ytop; (j >= ybottom) ; --j)    /* loop over raster lines */
  512.       {
  513.     if (isNul (BITMAP(j,0)))
  514.       ycnt ++;
  515.     else
  516.     {
  517.         if (ycnt) OUTF("\033*p+%dY",ycnt);
  518.         outline(BITMAP(j,0));
  519.         ycnt = 0;
  520.     }
  521.       }
  522. #else
  523.     for (j = ytop; (j >= ybottom) ; --j)    /* loop over raster lines */
  524.     outline(BITMAP(j,0));
  525. #endif /*YOFF*/
  526.  
  527.     OUTS("\033*rB\f");            /* end raster graphics, eject page */
  528.  
  529.     (void)fflush(plotfp);
  530.     if (DISKFULL(plotfp))
  531.     (void)fatal("Output error -- disk storage probably full");
  532. }
  533. #ifdef YOFF
  534. isNul (pbit) UNSIGN32 *pbit;    
  535. {
  536.   UNSIGN32 * p;
  537. #if    IBM_PC_MICROSOFT
  538.   int last_word;
  539.   for (last_word = XBIT - 1;
  540.     (last_word >= 1) && (*(UNSIGN32*)normaddr(pbit,last_word) == 0);
  541.     --last_word)
  542.         ;                /* trim white space a word at a time */
  543.    if (last_word <=1) return 1;
  544.    return 0;
  545. #else
  546.   p = pbit + XBIT - 1;        /* point to last word on line */
  547.   while ( !*p && p>pbit ) p--;
  548.   if (p==pbit && !*p) return 1;
  549.   return 0;
  550. #endif /*IBM_PC_MICROSOFT*/
  551. #endif /*YOFF*/
  552.  
  553. #include "outrow.h" 
  554. #include "prtpage.h" 
  555. #include "readfont.h" 
  556. #include "readgf.h" 
  557. #include "readpk.h" 
  558. #include "readpost.h" 
  559. #include "readpxl.h" 
  560. #include "reldfont.h" 
  561. #include "rulepxl.h" 
  562. #include "setchar.h" 
  563. #include "setfntnm.h" 
  564. #include "setrule.h" 
  565. #include "signex.h" 
  566. #include "skgfspec.h" 
  567. #include "skipfont.h" 
  568. #include "skpkspec.h" 
  569. #include "special.h" 
  570. #include "strchr.h" 
  571. #include "strcm2.h" 
  572. #include "strid2.h" 
  573. #include "strrchr.h" 
  574. #include "tctos.h" 
  575. #include "usage.h" 
  576. #include "warning.h"
  577.